package _01_动态数组;

public class _11_盛最多水的容器 {

    public static void main(String[] args) {
        _11_盛最多水的容器 v = new _11_盛最多水的容器();
        int[] ints = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(v.maxArea(ints));
    }

    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int max = 0;
        while (left < right) {
            int minHeight = Math.min(height[right], height[left]);
            // 求得当前盛水最多容器
            max = Math.max(max, (right - left) * minHeight);
            while (left < right && height[right] <= minHeight) right--;
            while (left < right && height[left] <= minHeight) left++;
        }
        return max;
    }

}
